﻿using Inv_4Service.dtos;
using NHibernateEntities.Dal;
using NHibernateEntities.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace Inv_4Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "BackOfficeService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select BackOfficeService.svc or BackOfficeService.svc.cs at the Solution Explorer and start debugging.
    public class BackOfficeService : IBackOfficeService
    {
        public CategoryDto[] GetCategories()
        {
         var result = new List<CategoryDto>();

            using (var session = NHibernateFactory.NHibernateHelper.OpenSession())
            {
                var list = CategoryDal.GetCategories(session);
                foreach (var item in list)
                {
                    var dto = new CategoryDto();
                    dto.Description = item.Description;
                    dto.Id = item.Id;
                    dto.Name = item.Name;
                    result.Add(dto);
                }
            }

            return result.ToArray();
        }
    }
}
